import 'package:easy_rich_text/easy_rich_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:xvideos/hj_model/video_model.dart';
import 'package:xvideos/routers/jump_router.dart';
import 'package:xvideos/hj_utils/date_time_util.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';

import '../../../../tools_base/richTextParsing/html_parser.dart';
import '../../../darkweb/widget/shrink_wrap.dart';
import '../../../home_business/widget/image_scale_view.dart';
import '../../community_tag_page/community_tag_page.dart';

class GameDetaiWordContent extends StatelessWidget {
  final VideoModel model;

  const GameDetaiWordContent(this.model, {super.key});

  @override
  Widget build(BuildContext context) {
    if (model.newsType != 'ADULT_GAME') return SizedBox.shrink();
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          '游戏介绍',
          style: TextStyle(color: Colors.white, fontSize: 16),
        ),
        18.sizeBoxH,
        Text(
          model.content ?? '',
          style: TextStyle(color: Colors.white, fontSize: 16),
        ),
      ],
    );
  }
}

class PostDetailWordContent extends StatelessWidget {
  final VideoModel model;

  const PostDetailWordContent({super.key, required this.model});

  @override
  Widget build(BuildContext context) {
    if (model.newsType == 'ADULT_GAME') return SizedBox.shrink();
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        14.sizeBoxH,
        if (model.title?.isNotEmpty == true)
          Container(
            padding: EdgeInsets.only(bottom: 1.h),
            child: Text(
              model.title ?? "",
              style: TextStyle(color: Color(0xFFDCDCDC), fontSize: 14.sp),
            ),
          ),
        _buildTagItem(),
        12.h.sizeBoxH,
        Divider(
          height: .5,
          color: Colors.white.withOpacity(.05),
        ),
        18.h.sizeBoxH,
        if (model.richText?.isNotEmpty == true)
          _buildRichTextContent()
        else if (model.content?.isNotEmpty == true)
          Container(
            padding: EdgeInsets.only(bottom: 18.h),
            child: Text(
              model.content ?? "",
              style: TextStyle(color: Color(0xFFDCDCDC), fontSize: 14.sp),
            ),
          )
        else
          SizedBox(),
      ],
    );
  }

  Widget _buildRichTextContent() {
    return DefaultTextStyle(
      style: TextStyle(color: Colors.white),
      child: Wrap(
        alignment: WrapAlignment.start,
        children: HtmlParser(
            width: double.infinity,
            onLinkTap: (url) {
              pushToPageByLink(url);
            },
            imgLinkTap: (url) {
              Get.to(ImageScaleView(url: url, isPage: true));
            }).parse(model.richText ?? ""),
      ),
    );
  }
  Widget _buildTagItem() {
    if (model.tags?.isNotEmpty == true) {
      return Container(
        padding: EdgeInsets.only(top: 10),
        child: ShrinkWrap(
          spacing: 0,
          runSpacing: 6,
          maxLines: 1,
          children: model.tags
              ?.map((e) => InkWell(
            onTap: () {
              Get.to(CommunityTagDetailPage(), arguments: e);
              // widget.controller?.pause();
              // Get.to(VideoTagPage(e, isShortStyle: true), preventDuplicates: true);
            },
            child: Container(
              padding: EdgeInsets.fromLTRB(8, 3, 8, 3),
              margin: EdgeInsets.only(right: 6),
              decoration: BoxDecoration(
                color: Color(0x0DFFFFFF),
                borderRadius: BorderRadius.circular(3),
              ),
              child: Text(
                "#${e.name}",
                style: TextStyle(
                  color: Color(0x73FFFFFF),
                  fontSize: 12,
                ),
              ),
            ),
          ))
              .toList() ??
              [],
        ),
      );
    }
    return const SizedBox();
  }
}
